//
//  ViewController.m
//  摇晃碎屏
//
//  Created by Justsoso on 16/4/5.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "ViewController.h"

#import <AudioToolbox/AudioToolbox.h>

#import <CoreMotion/CoreMotion.h>

@interface ViewController ()
{
    SystemSoundID soundID;
}
@property (weak, nonatomic) IBOutlet UIImageView *imageView;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}


#pragma mark - 检测运动
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    self.imageView.highlighted = YES;
    if (soundID == 0)
    {
        NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"glass" withExtension:@"wav"];
        
        AudioServicesCreateSystemSoundID((__bridge CFURLRef _Nonnull)(fileURL), &soundID);
    }
    AudioServicesPlaySystemSound(soundID);
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    self.imageView.highlighted = NO;
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}
@end
